# -*- coding: UTF-8 -*-
from naoqi import qi
import time

class Sensor():
    def __init__(self,mem):
        self.mem =mem
        self.mem.insertData("Device/SubDeviceList/US/Actuator/Value",68.0)
        #记录起始z轴方向
        self.origin_gyro=self.mem.getData("Device/SubDeviceList/InertialSensor/AngleZ/Sensor/Value")
        self.limit=0.3
    def get_sonar_data(self):
        left_data=self.mem.getData("Device/SubDeviceList/US/Left/Sensor/Value")
        right_data=self.mem.getData("Device/SubDeviceList/US/Right/Sensor/Value")
        return [left_data,right_data]
    def sonar_no_obstacle(self):
        data=self.get_sonar_data()
        if data[0]< self.limit or data[1]<self.limit:
            return False
        else:
            return True
    def get_gyro_info(self):
        z = self.mem.getData("Device/SubDeviceList/InertialSensor/AngleZ/Sensor/Value")
        return z-self.origin_gyro

# mySonar=Sonar()
# while True:
#     data=mySonar.get_sonar_data()
#     print(data)
#     print(mySonar.sonar_no_obstacle())
#     time.sleep(1)